<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/2/7
 * Time: 9:30
 */

namespace app\common;


use app\common\model\Sellers;
use app\common\model\Users;

class Notify
{
    private static function base_send($cid, $msg)
    {
        if (!$cid) {
            return false;
        }
        $msg = json_encode($msg);
        common_vendor("getui.GetUiClient");
        \GetUiClient::send($cid, $msg);
        return true;
    }

    static function send($user_id, $msg)
    {
        $user = Users::get(["id"=>$user_id]);
        if (isset($user->client_id)) {
            return self::base_send($user->client_id, $msg);
        }
        return false;
    }

    static function seller_send($seller_id, $msg)
    {
        $seller = Sellers::get($seller_id);
        if (isset($seller->user_id)) {
            return self::send($seller->user_id, $msg);
        }
        return false;
    }
}